const {GeneratedType, Registry} = require("@cosmjs/proto-signing");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing")
const { SigningStargateClient, StargateClient } = require("@cosmjs/stargate")
const { stringToPath } = require("@cosmjs/crypto")
const config = require('./config')

let rpc = config.noble.url;

rpc = "http://37.27.111.140:41005"

const main = async() => {
    console.log('config.mnemonic: ', config.MNEMONIC);

    const mnemonic = config.MNEMONIC;
    const wallet1 = await DirectSecp256k1HdWallet.fromMnemonic(
        mnemonic,
        {
            hdPaths: [stringToPath("m/44'/118'/0'/0/0")],
            prefix: "noble"
        }
    );

    const [account] = await wallet1.getAccounts();

    console.log(account.address)

    const client = await StargateClient.connect(rpc)
    console.log("With client, chain id:", await client.getChainId(), ", height:", await client.getHeight())
    console.log(
        account.address, "- balances:",
        await client.getAllBalances(account.address)
    )
    let tx = await client.getTx("6B512C3885DF36A2D9BBBB20B32F2A07AC818A8A9BAB768231DCE8C15FA0064F");
    console.log('tx: ', tx);
}
main();